﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.ComponentModel;
using System.Windows.Forms;

namespace hpm
{
    class clsTinh
    {
        DAL da = new DAL();
        public DataTable dtbTinh;
        SqlCommand slqcom;
        SqlDataAdapter sqlDataAdapter = null;

        string _maTinh, _tenTinh, _maVung;

        public string MaTinh { get; set; }
        public string TenTinh { get; set; }
        public string MaVung { get; set; }

        public clsTinh()
        {
            this._maTinh = this._tenTinh = this._maVung = "";
        }


        public DataTable getAllTinh()
        {
            da.ketnoiServer();
            dtbTinh = new DataTable();
            this.slqcom = new SqlCommand();
            this.slqcom.CommandText = "Select MaTinh, TenTinh from DMTinh order by TenTinh";
            this.slqcom.Connection = da.con;
            this.slqcom.CommandType = CommandType.Text;
            this.sqlDataAdapter = new SqlDataAdapter(this.slqcom);
            this.sqlDataAdapter.Fill(dtbTinh);
            da.da_closeConnect();
            return dtbTinh;
        }

        public string getMacDinh()
        {
            da.ketnoiServer();
            this.slqcom = new SqlCommand();
            this.slqcom.CommandText = "Select TenTinh from DMTinh WHERE MacDinh = 1";
            this.slqcom.Connection = da.con;
            SqlDataReader reader = slqcom.ExecuteReader();
            reader.Read();
            return reader[0].ToString();
        }
    }
}
